package com.weed.helper;

import com.weed.common.Log;
import com.weed.common.Configuration;

import com.weed.common.Environment;

/**
 * 函数说明:
 *     日志工厂，用于产生日志对象.
 *
 * 版本    修订人        说明
 * 0.1    Jason Zhuo    新增日志工厂
 */


public class LogFactory
    extends Factory {

  static Factory factory = null;

  private LogFactory() {}

  /**
   * 初始化日志对象.
   * @param clazz 出现异常的对象．
   */
  public static Log getLog(Class clazz) {
    Config config = null;
    try {
      config = Configuration.config();
      if (factory == null) {
        factory = new LogFactory();
      }
      Object logObject = null;
      String logclass = "";
      if((logclass = config.getImplementClass(Environment.DEFAULT_LOG_IMPL))!=null){
            logObject = factory.newInstace(logclass);
      }
      if (logObject != null){
          ((Log) logObject).init(clazz);
          return (Log) logObject;
      }
    }
    catch (Exception ex) {
        System.out.println("" + ex);
    }finally{
        config = null;
    }
    return null;
 }
    public static void main(String[] args){
        LogFactory.getLog(LogFactory.class).debug("调试信息。");
    }
    /**
   * 初始化日志对象.
   * @param clazz 出现异常的对象．
   */
//  public static Log getLog(Class clazz) {
//    Config config = null;
//    try {
//      config = Configuration.config();
//      if (factory == null) {
//        factory = new LogFactory();
//      }
//      Object logObject = factory.newInstace(config.getImplementClass(Environment.DEFAULT_LOG_IMPL));
//      if (logObject != null){
//          ((Log) logObject).init(clazz);
//          return (Log) logObject;
//      }
//    }
//    catch (Exception ex) {
//      ex.printStackTrace();
//    }finally{
//         config = null;
//    }
//    return null;
// }
}
